﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.Ccr.Core;
using NUnit.Framework;
using XcoAppSpaces.Core;
using XcoAppSpaces.Contracts.Security;
using XcoAppSpaces.Security.Basic;

namespace test.XcoAppSpaces.Core.Error_Reproductions
{
	[TestFixture]
	public class testSecurityWithMultipleWorkers
	{
		class WindowsUpdates : PortSet<string, int> { }

		[XcoSecurityPermission("WindowsUpdateWorkerRole")]
		class WindowsUpdateWorker : WindowsUpdates { }

		class ShutDownControl : PortSet<string, int> { }

		[XcoSecurityPermission("ShutDownWorkerRole")]
		class ShutDownWorker : ShutDownControl { }


		[Test]
		public void Test()
		{
			var security = new XcoBasicSecurityService();
			security.AddUser("jan", "blub", "ShutDownWorkerRole");
			security.AddUser("mimi", "bla", "WindowsUpdateWorkerRole");

			using (XcoAppSpace space = XcoAppSpace.ConfigureWithConfigString("tcp.port=9000").UsingService(security))
			{
				space.RunWorker<WindowsUpdates, WindowsUpdateWorker>("RMService");
				space.RunWorker<ShutDownControl, ShutDownWorker>("RMService");

				Thread.Sleep(1000);
				Console.WriteLine("Successful");
			}
		}
	}
}
